package contegor.scire.structure.queries;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import contegor.scire.core.Id;
import contegor.scire.core.Link;
import contegor.scire.core.Version;
import contegor.scire.core.queries.Condition;
import contegor.scire.core.queries.GetConcepts;
import contegor.scire.core.queries.GetLinksFromTargets;
import contegor.scire.core.queries.GetSourcesFromLinks;
import contegor.scire.core.queries.Query;

/**
 * Base for many recursive {@link Query}s.
 *
 * @version $Revision$
 * @author  Héctor Cirbián Pousa ($Author$)
 */
@Version("$Id$")
public class BaseRecursiveQuery extends GetSourcesFromLinks {
  private static final long serialVersionUID = -4385138940211787577L;

  @SuppressWarnings("unchecked")
  public BaseRecursiveQuery(Id id, Condition<Link> select, Condition<Link> accept) {
    super(id.getParentId());
    List<Query<Link>> aux = new ArrayList<Query<Link>>(1);
    aux.add(new GetLinksFromTargets(new GetConcepts(id.getParentId(), id.getLastIdFragment()))
                  .withIt(new RecursiveQuery<Link>(id.getParentId(),
                                                   new Replicator<CircularGetLinksDownstream>(CircularGetLinksDownstream.class),
                                                   select,
                                                   accept)));
    this.dependencies = Collections.unmodifiableList(aux);
  }
}